package ex_from_web;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class links_list_and_arrays {
	public static void main(String[] args) {
	    //Insted of ArrayList, you can use 
	    //Vector or LinkedList as well
	    List<String> list = new ArrayList<String>();
	    list.add("Element 1");
	    list.add("Element 2");
	    list.add("Element 3");
	    
	    System.out.println("For loop 1");
	    for (int i = 0; i < list.size(); i++) {
	        String s = list.get(i);
	        System.out.println(s);
	    }
	    
	    System.out.println("For loop 2"); //since Java 5
	    for (String s : list) {
	        System.out.println(s);
	    }
	    
	    System.out.println("Iterator");
	    Iterator<String> li = list.iterator();
	    while (li.hasNext()) {
	        String s = li.next();
	        System.out.println(s);
	    }
	    
	    System.out.println("While loop");
	    int i = 0;
	    while(i < list.size()) {
	        String s = list.get(i);
	        System.out.println(s);
	        i++;
	    }
	    
	    System.out.println("Do loop");
	    i = 0;
	    do {
	        String s = list.get(i);
	        System.out.println(s);
	        i++;
	    } while(i < list.size());
	   }

}
